package com;

import com.netflix.config.ConfigurationManager;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

public class CurcuitBreakerDemo extends HystrixCommand<String>{

	public CurcuitBreakerDemo() {
		super(HystrixCommandGroupKey.Factory.asKey("CurcuitBreaker"));
	}
	
	protected String run() {
		System.out.println("In run");
		return "run";
	}

	protected String getFallback() {
		System.out.println("In FallBack");
		return "In FallBack";
	}
	
	public static void main(String[] args) {
		// 断路器被强制打开
				ConfigurationManager.getConfigInstance().setProperty(
						"hystrix.command.default.circuitBreaker.forceOpen", "true");
				CurcuitBreakerDemo demo1 = new CurcuitBreakerDemo();
				demo1.execute();
				// 创建第二个命令，断路器关闭
				ConfigurationManager.getConfigInstance().setProperty(
						"hystrix.command.default.circuitBreaker.forceOpen", "false");
				CurcuitBreakerDemo demo2 = new CurcuitBreakerDemo();
				demo2.execute();

	}

}
